from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QStyle
from PySide6.QtCore import QSize

class Resources:
    """资源管理器"""
    
    def __init__(self):
        self._icons = {
            'folder': self._get_std_icon('SP_DirIcon'),
            'import': self._get_std_icon('SP_FileIcon'),
            'export': self._get_std_icon('SP_DialogSaveButton'),
            'table': self._get_std_icon('SP_FileDialogListView'),
            'chart': self._get_std_icon('SP_FileDialogDetailedView'),
            'stats': self._get_std_icon('SP_FileDialogInfoView'),
            'refresh': self._get_std_icon('SP_BrowserReload'),
        }
    
    def _get_std_icon(self, name: str) -> QIcon:
        """获取标准图标"""
        style = QApplication.instance().style()
        icon = style.standardIcon(getattr(QStyle, name))
        return icon
    
    def icon(self, name: str) -> QIcon:
        """获取图标"""
        return self._icons.get(name, QIcon())
    
    def pixmap(self, name: str, size: QSize = None) -> QPixmap:
        """获取像素图"""
        icon = self.icon(name)
        if size is None:
            size = QSize(32, 32)
        return icon.pixmap(size)